package com.design.fitment.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.design.fitment.R;
import com.design.fitment.app.MyApplication;
import com.design.fitment.entity.JieXiDetail;
import com.design.fitment.util.DesignNetworkUtil;
import com.design.fitment.util.RequestDataCallback;
import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 娇哥 on 2016/1/16.
 */
public class JieXiDetailHeaderView extends FrameLayout {
    private Context context;
    private List<JieXiDetail.DataEntity> mList = new ArrayList<>();
    @ViewInject(R.id.iv_jiexi_detail)
    private ImageView ivJiexiDetail;
    @ViewInject(R.id.tv1_jiexi_detail)
    private TextView tv1JiexiDetail;
    @ViewInject(R.id.tv2_jiexi_detail)
    private TextView tv2JiexiDetail;
    @ViewInject(R.id.iv_jiexi_detail_header_round)
    private RoundImageView ivJiexiDetailHeaderRound;
    @ViewInject(R.id.tv_detail_content)
    private TextView tvJiexiContent;
    private ImageLoader imageLoader;
    private DisplayImageOptions options;
    private int casesId;
    public JieXiDetailHeaderView(Context context,int casesId) {
        super(context);
        this.context = context;
        this.casesId = casesId;
        initViews();

    }
    private void initViews() {
        View view =  LayoutInflater.from(context).inflate(R.layout.jiexi_detail, this, true);
        ViewUtils.inject(this, view);
        imageLoader = MyApplication.getApp().getImageLoader();
        options = MyApplication.getApp().getImageOptions();

    }

    public  void load(){
        DesignNetworkUtil.getInstance().getJieXiDetail(new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
                Gson gson = new Gson();
                JieXiDetail detail = gson.fromJson(response, JieXiDetail.class);
                if (detail != null) {
                    JieXiDetail.DataEntity data = detail.getData();
                    imageLoader.displayImage(data.getImgUrl(), ivJiexiDetail, options);
                    imageLoader.displayImage(data.getMemberInfo().getFacePic(), ivJiexiDetailHeaderRound, options);
                    tv1JiexiDetail.setText(data.getName());
                    tv2JiexiDetail.setText(data.getMemberInfo().getNick());
                    tvJiexiContent.setText(data.getComment());


                }

            }

            @Override
            public void onFailure(HttpException error) {

            }
        }, casesId);
    }

}
